package java学习.JUC;

import java.util.concurrent.*;

/**
 * **************
 * 项目名称: 蓝桥杯 <br/>
 * 文件名称:  <br/>
 * 文件描述: 这里添加您的类文件描述，说明当前文件要包含的功能。 <br/>
 * 文件创建：刘世锦 <br/>
 * 创建时间: 2022/6/5 <br/>
 *
 * @version v1.0 <br/>
 * @update [序号][日期YYYY-MM-DD][更改人姓名][变更描述]<br/>
 * *************
 */
public class Threadpool {
    public static void main(String[] args) {
//        ThreadPoolExecutor executor = new ThreadPoolExecutor();
        ExecutorService threadPool1 = Executors.newFixedThreadPool(3);

        ExecutorService threadPool3 = Executors.newSingleThreadExecutor();

        ExecutorService threadPool2 = Executors.newCachedThreadPool();

        ThreadPoolExecutor threadPool4 = new ThreadPoolExecutor(
                2, 5, 2L,
                TimeUnit.SECONDS, new ArrayBlockingQueue<>(3),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
        try {
                for (int i = 1; i <=10; i++) {
                    threadPool4.execute(new Runnable() {
                    @Override
                    public void run() {
                        System.out.println(Thread.currentThread().getName());
                    }
                });
                }

            }catch (Exception e){
                e.printStackTrace();
            }finally {
            threadPool4.shutdown();
            }

        }
}
